package com.handong.handserialprogram.thread;

import com.handong.handserialprogram.utils.JLog;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;

public class MinaClientHandler extends IoHandlerAdapter {

    private static final String TAG = "MinaClientHandler";

    @Override
    public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        JLog.d(TAG, "客户端发生异常:" + cause.toString());
        super.exceptionCaught(session, cause);
    }

    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {
//        String msg = message.toString();
//
//        Charset charset = Charset.forName("UTF-8");
//        CharsetDecoder decoder = charset.newDecoder();
//
//        IoBuffer ioBuffer = (IoBuffer) message;
//        String cmd = ioBuffer.getString(decoder);
//        JLog.d(TAG, "i客户端接收到的信息为:" + msg + " ||| 解析结果：" + cmd);
        super.messageReceived(session, message);
    }

    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
        JLog.d(TAG, "i客户端发送的信息为:" + message.toString());
        super.messageSent(session, message);
    }
}
